import { UserProfilesAPI } from "@/request/API";
export default {
    namespaced: true,
    state: {
        userInfo: {
            nickName: 'shabi',
            coin: 99,
            headImg: require("../../assets/img/monad.png")
        },
        cartTotal: 88
    },
    mutations: {
        //修改登陆状态
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo
            state.cartTotal = payload.cartTotal
        },
        //初始化仓库属性
        initUserInfo(state) {
            state.userInfo = {
                //昵称
                nickName: 'shabi',
                coin: 99,
                headImg: require("../../assets/img/monad.png")
            }
            state.cartTotal = 88
        }
    },
    actions: {
        //请求用户信息
        async asyncchangeUserInfo({ commit }) {
            //1.请求用户信息
            let user = await UserProfilesAPI();
            // console.log("获取用户信息", user);
            //2.更新vuex中用户信息，调用mutations
            commit("changeUserInfo", user.data)
        }
    }
}